import { defHttp } from '/@/utils/http/axios';
import {
  OpmsDistressReliefListGetResultModel,
  OpmsDistressReliefModel,
  OpmsDistressReliefPageListGetResultModel,
  OpmsDistressReliefParams,
  OpmsDistressReliefPageSearchParams,
  OpmsDistressReliefListSearchParams,
  UpdateOpmsDistressReliefParams,
  OpmsDistressReliefIDType,
} from '/@/api/distress/model/OpmsDistressReliefModel';

import { UploadFileParams } from '/#/axios';
import { useGlobSetting } from '/@/hooks/setting';
import { UploadApiResult } from '../sys/model/uploadModel';

// 困难救助表接口
export enum Api {
  PublicApi = '/distress/opms-distress-relief',
  ListApi = `/distress/opms-distress-relief/list`,
  PageApi = `/distress/opms-distress-relief/page`,
  BatchApi = `/distress/opms-distress-relief/batch`,
  ExportApi = `/distress/opms-distress-relief/export`,
  ImportApi = `/distress/opms-distress-relief/import`,
  DownloadApi = `/distress/opms-distress-relief/download`,
  UploadFileApi = `/api/distress/opms-distress-relief/uploadFile`,
}
/**
 * @description:  获取列表
 * @param params
 * @returns
 */
export const getOpmsDistressReliefList = (params?: OpmsDistressReliefListSearchParams) =>
  defHttp.get<OpmsDistressReliefListGetResultModel>({ url: Api.ListApi, params });

/**
 * @description:  分页获取列表
 * @param params
 * @returns
 */
export const getOpmsDistressReliefPage = (params: OpmsDistressReliefPageSearchParams) =>
  defHttp.get<OpmsDistressReliefPageListGetResultModel>({ url: Api.PageApi, params });

/**
 * @description:  根据id获取
 * @param id
 * @returns
 */
export const getOpmsDistressRelief = (id: OpmsDistressReliefIDType) =>
  defHttp.get<OpmsDistressReliefModel>({ url: `${Api.PublicApi}/${id}` });

/**
 * @description:  创建
 * @param params
 * @returns
 */
export const createOpmsDistressRelief = (params: OpmsDistressReliefParams) =>
  defHttp.post<boolean>({ url: Api.PublicApi, params });

export const download = (params?) =>
  defHttp.post({ url: Api.DownloadApi, responseType: 'blob', params });

export const uploadOpmsFile = (
  params: UploadFileParams,
  onUploadProgress?: (progressEvent: ProgressEvent) => void,
) =>
  defHttp.uploadFile<UploadApiResult>(
    {
      url: useGlobSetting().apiUrl + Api.UploadFileApi,
      onUploadProgress,
    },
    params,
  );

/**
 * @description:  更新
 * @param params
 * @returns
 */
export const updateOpmsDistressRelief = (params: UpdateOpmsDistressReliefParams) =>
  defHttp.put<boolean>({ url: Api.PublicApi, params });

/**
 * @description:  物理删除
 * @param id
 * @returns
 */
export const deleteOpmsDistressRelief = (id: OpmsDistressReliefIDType) =>
  defHttp.delete<boolean>({ url: `${Api.PublicApi}/${id}` });

/**
 * @description:  物理批量删除
 * @param ids
 * @returns
 */
export const deleteOpmsDistressReliefBatch = (ids: OpmsDistressReliefIDType[]) =>
  defHttp.post<boolean>({ url: Api.BatchApi, params: { ids } });

/**
 * @description:  逻辑删除
 * @param ids
 * @returns
 */
export const logicDeleteOpmsDistressRelief = (id: OpmsDistressReliefIDType) =>
  defHttp.delete<boolean>({ url: `${Api.PublicApi}/${id}` });

/**
 * @description:  逻辑批量删除
 * @param ids
 * @returns
 */
export const logicDeleteOpmsDistressReliefBatch = (ids: OpmsDistressReliefIDType[]) =>
  defHttp.post<boolean>({ url: Api.BatchApi, params: { ids } });

/**
 * @description:  导出文件
 * @param ids
 * @returns
 */
export const exportOpmsDistressReliefListFile = (ids: OpmsDistressReliefIDType[]) =>
  defHttp.post<boolean>({ url: Api.ExportApi, params: { ids } });

/**
 * @description:  导入文件
 * @param ids
 * @returns
 */
export const importOpmsDistressReliefListFile = (
  params: UploadFileParams,
  onUploadProgress?: (progressEvent: ProgressEvent) => void,
) =>
  defHttp.uploadFile<UploadApiResult>(
    {
      url: useGlobSetting().apiUrl + Api.ImportApi,
      onUploadProgress,
    },
    params,
  );
